package top.aiprogram.controller;

import org.apache.commons.io.FileUtils;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import top.aiprogram.po.Items;
import top.aiprogram.po.User;
import top.aiprogram.service.ItemService;

import javax.annotation.Resource;
import java.io.File;
import java.io.IOException;

/**
 * Created by ASUS on 2017/6/13.
 */
@Controller
@RequestMapping("/user")
public class UserController {

    @Resource(name = "itemServiceImpl")
    private ItemService itemService;

    @RequestMapping("/test/{id}/{name}")
    public String add(@PathVariable Integer id, @PathVariable String name){
        System.out.println(id);
        System.out.println(name);
        return "user";
    }
    @RequestMapping("/userjson")
    public @ResponseBody
    User userJson(){
        User user = new User();
        user.setId(23);
        user.setUsername("lao");
        return user;
    }


//    @RequestMapping("/down")
//    public ResponseEntity<byte[]> download() throws IOException {
//        String path = "d:/a.txt";
//        File file = new File(path);
//        HttpHeaders headers = new HttpHeaders();
//        headers.setContentDispositionFormData("attachment",path);
//        headers.setContentType(MediaType.TEXT_HTML);
//
//        return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file),headers, HttpStatus.CREATED);
//
//
//
//    }
    @RequestMapping("/item/{id}")
    public String findItemsById(@PathVariable Integer id) throws Exception {

        Items items = itemService.findById(id);
        return null;
    }


}
